In this assignment we will look at the Facility Location Problem. The problem can be described in general terms as follows:
We must decide the placement of a facility that distributes a certain good to a group of consumers that need it.
The placement must to be chosen in order to minimize the total compound distance from the facility and the customers.
The following assumptions has to be taken into account:
Notice that in this scenario there is one possible decision to make:
A file with the locations of the consumers can be found in the Data folder.
Given the position of the facility \(f= (\chi, \upsilon)\) and of a consumer \(p_i=(x_i, y_i)\) use the following formula to calculate the distance between them.
\[ d(f,p_i) = log((\chi-x_i)^2+1) + log((\upsilon-y_i)^2+1) \] #Carico le coordinate su una variabile:
library(ggplot2)
coordinate<-read.csv("/Users/lorenzofamiglini/Downloads/consumer_locations.csv")
\[ min \ f(\chi, \upsilon) \\ \text{ dove }f(\chi,\upsilon)=\sum_{i=1}^{n} log((\chi-x_i)^2+1) + log((\upsilon-y_i)^2+1) \] Le derivate parziali sono: \[ ∂/∂\chi = \sum_{i=1}^{n}(2(\chi-x_i)/(\chi-x_i)^2 + 1) \\ ∂/∂\upsilon = \sum_{i=1}^{n}(2(\upsilon-y_i)/(\upsilon-y_i)^2 + 1) \] Rappresentiamo la funzione in 3D:
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plottare <- function(x, y){
distanza <- 0
for (i in 1:nrow(coordinate)){
distanza <- distanza + log((x-coordinate$x[i])^2+1) + log((y - coordinate$y[i])^2 + 1)
}
return(distanza)
}
x <- seq(0, 1000)
y <- x
z = outer(x, y, plottare)
plt <- plot_ly(z = ~ z, colors = c("blue","grey")) %>% add_surface(
contours = list(
z = list(
show = TRUE,
usecolormap = TRUE,
highlightcolor = "#ff0001",
project = list(z = TRUE)
)
)
) %>%
layout(
scene = list(
camera = list(
eye = list(x = 1.87, y = 0.88, z = - 0.64)
)
)
)
plt